	var map = new BMap.Map("map");                        // 创建Map实例
	var gc = new BMap.Geocoder();
	map.centerAndZoom(new BMap.Point(118.723572,32.211126), 15);  //定位南信大
	//地图样式
	var mapStyle={style:"mapbox"};
	map.setMapStyle(mapStyle);
	var geolocation = new BMap.Geolocation();
	geolocation.getCurrentPosition(function(r){
		if(this.getStatus() == BMAP_STATUS_SUCCESS){
			var pt = r.point;
			gc.getLocation(pt,function(rs){
				var addComp = rs.addressComponents;
				map.centerAndZoom(addComp.city,13);
			})
		}
	})
    map.enableScrollWheelZoom();                        //启用滚轮放大缩小
        var points = [];  // 添加海量点数据
        var polyPoints = [];	//添加路径点
        $.getJSON('/gradesign/map/paydata',function(data){
        	
        	for(var i=0;i<data.data.length;i++){
        		points.push([data.data[i].lng,data.data[i].lat,"项目："+data.data[i].item+"</br>花费："+data.data[i].money+"</br>日期："+data.data[i].date+"</br>地址："+data.data[i].address]);
        		polyPoints.push(new BMap.Point(data.data[i].lng,data.data[i].lat));
        	}
        	
        	//	坐标连成轨迹
        	var polyline = new BMap.Polyline(polyPoints,{strokeStyle:"dashed",strokeColor:"green", strokeWeight:2, strokeOpacity:1});
        	
        	map.addOverlay(polyline);
        	addArrow(polyline,10,Math.PI/7);
//        	addArrow(polyline,10,Math.PI/7);
//        	var myIcon = new BMap.Icon("http://lbsyun.baidu.com/jsdemo/img/fox.gif", new BMap.Size(300,157));
        	//var myIcon = new BMap.Icon("/gradesign/img/funny.gif", new BMap.Size(300,457));
        	//points = [[118.723572,32.211126,"第一个地址"],[118.733572,32.231126,"第二个地址"]];
        	for(var i=0;i<points.length;i++){
        		//	自定义地图标注点
//            	var marker = new BMap.Marker(new BMap.Point(points[i][0],points[i][1]),{icon:myIcon});
        		//	默认地图标注点
        		var marker = new BMap.Marker(new BMap.Point(points[i][0],points[i][1]));
            	var content = points[i][2];
            	map.addOverlay(marker);
            	addClickHandler(content,marker);
            }
            function addClickHandler(content,marker){
            	marker.addEventListener("click",function(e){
            		openInfo(content,e);
            	});
            }
            var opts = {
    				width : 100,     // 信息窗口宽度
    				height: 120,     // 信息窗口高度
    				title : "消费信息" , // 信息窗口标题
    				enableMessage:true//设置允许信息窗发送短息
    			   };
            function openInfo(content,e){
        		var p = e.target;
        		var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
        		var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象 
        		map.openInfoWindow(infoWindow,point); //开启信息窗口
        	}
        });
        function addArrow(polyline,length,angleValue){ //绘制箭头的函数  
        	var linePoint=polyline.getPath();//线的坐标串  
        	var arrowCount=linePoint.length;  
        	for(var i =1;i<arrowCount;i++){ //在拐点处绘制箭头  
        	var pixelStart=map.pointToPixel(linePoint[i-1]);  
        	var pixelEnd=map.pointToPixel(linePoint[i]);  
        	var angle=angleValue;//箭头和主线的夹角  
        	var r=length; // r/Math.sin(angle)代表箭头长度  
        	var delta=0; //主线斜率，垂直时无斜率  
        	var param=0; //代码简洁考虑  
        	var pixelTemX,pixelTemY;//临时点坐标  
        	var pixelX,pixelY,pixelX1,pixelY1;//箭头两个点  
        	if(pixelEnd.x-pixelStart.x==0){ //斜率不存在是时  
        	    pixelTemX=pixelEnd.x;  
        	    if(pixelEnd.y>pixelStart.y)  
        	    {  
        	    	pixelTemY=pixelEnd.y-r;  
        	    }  
        	    else  
        	    {  
        	    	pixelTemY=pixelEnd.y+r;  
        	    }     
        	    //已知直角三角形两个点坐标及其中一个角，求另外一个点坐标算法  
        	    pixelX=pixelTemX-r*Math.tan(angle);   
        	    pixelX1=pixelTemX+r*Math.tan(angle);  
        	    pixelY=pixelY1=pixelTemY;  
        	}  
        	else  //斜率存在时  
        	{  
        	    delta=(pixelEnd.y-pixelStart.y)/(pixelEnd.x-pixelStart.x);  
        	    param=Math.sqrt(delta*delta+1);  
        	    if((pixelEnd.x-pixelStart.x)<0) //第二、三象限  
        	    {  
	        	    pixelTemX=pixelEnd.x+ r/param;  
	        	    pixelTemY=pixelEnd.y+delta*r/param;  
        	    }  
        	    else//第一、四象限  
        	    {  
	        	    pixelTemX=pixelEnd.x- r/param;  
	        	    pixelTemY=pixelEnd.y-delta*r/param;  
        	    }  
        	    //已知直角三角形两个点坐标及其中一个角，求另外一个点坐标算法  
        	    pixelX=pixelTemX+ Math.tan(angle)*r*delta/param;  
        	    pixelY=pixelTemY-Math.tan(angle)*r/param;  
        	    pixelX1=pixelTemX- Math.tan(angle)*r*delta/param;  
        	    pixelY1=pixelTemY+Math.tan(angle)*r/param;  
        	}  
        	var pointArrow=map.pixelToPoint(new BMap.Pixel(pixelX,pixelY));  
        	var pointArrow1=map.pixelToPoint(new BMap.Pixel(pixelX1,pixelY1));  
        	var Arrow = new BMap.Polyline([  
        	    pointArrow,  
        	 linePoint[i],  
        	    pointArrow1  
        	], {strokeStyle:"dashed",strokeColor:"green", strokeWeight:2, strokeOpacity:1});  
        	map.addOverlay(Arrow);  
        	}  
}